<script setup>
	import FirstTitle from "@comp/FirstTitle";
	import {
		Editor,
		Toolbar
	} from "@wangeditor/editor-for-vue";
	import {
		onMounted
	} from "vue";
	
	import {
		searchDataQbxx
	} from "@/api/search";
	import {
		addOrUpdateQbxx
	} from "@/api/addOrUpdate";
	
	import { postTableData } from "@/api/table";


	const city = window.globalObj.name;
	const editorRef = shallowRef();

	const toolbarConfig = {};
	const editorConfig = {
		placeholder: "请输入内容..."
	};
	const mode = ref("default");

	// 加载html
	const initHtml = () => {
		searchDataQbxx({ m: "情报获取" }).then((res) => {
			const { data } = res
			valueHtml.value = data.find((x) => x.k === "情报获取")?.v || "";
		})
	};

	const handleCreated = (editor) => {
		editorRef.value = editor; // 记录 editor 实例，重要！
	};

	const valueHtml = ref(
	"1.战区联指情报信息获取<br/>主要任务：接收战区联指提供的战场态势信息、实时空情信息和敌特活动情报信息。<br/>设备调配：空情接收自动化系统、一体化联合作战指挥软件（军用）、前置服务器、筛选服务器等。<br/>软件部署：空情预警信息软件、一体化联合作战指挥软件（军用）。<br/>网络连接：人防专网、军网。<br/>2.观察员情报信息获取<br/>主要任务：观察、侦搜可能来袭的空中目标、空袭情况，并及时上报。<br/>3.低空预警雷达探测情报信息<br/>主要任务：预警探测低空飞行器。<br/>4.重要目标警戒情报信息<br/>主要任务：获取重要目标警戒情报信息。<br/>网络连接：人防专网、有线电话。"
	);

	const saveProgramme = () => {
		ElMessageBox.confirm(`确定要保存吗?`, "警告", {
			confirmButtonText: "确定",
			cancelButtonText: "取消",
			type: "warning",
			customClass: "message-box",
		}).then(() => {
			addOrUpdateQbxx({
					m: "情报获取",
					data: [{
						k: "情报获取",
						v: valueHtml.value,
					}],
				})
				.then((result) => {
					if (result.code === 200){
						 ElMessage.success("操作成功");
						 initHtml();
					} else {
						ElMessage.error(result.msg);
					}
				})
				.catch(() => {});
		});
	}

	onMounted(() => {
		initHtml();

	});
	onBeforeUnmount(() => {
		const editor = editorRef.value;
		if (!editor) return;
		editor.destroy();
	
	});
	
	// 表头单元格样式
	const headerCellStyle = () => {
		return {
			backgroundColor: "#f5f7fa",
			color: "rgba(0,0,0,0.85)",
			fontSize: "14px",
			height: "54px",
		};
	};
	// 单元格样式
	const cellStyle = () => {
		return {
			color: "rgba(0,0,0,0.65)",
			fontSize: "14px",
			lineHeight: "22px",
		};
	};
	
	const tableData = ref([])
	const getList = () => {
		postTableData({
			docType: "intelligence",
			method: "zhongyaomubiaoxinxi",
		}).then(result=>{
			if(result.code === 200){
				tableData.value = result.data
			}
		})
	}
	getList()
	
	
</script>
<template>
	<div class="">
		<FirstTitle name="情报获取" />
		
		<div class="top-15">
			主要获取上级提供的战略情报、战场态势、实时空情、敌特活动等情报信息，以及本级侦搜的对空目力观察、低空预警雷达探测、重要目标警戒等情报信息。
		</div>
		
		<div style="border: 1px solid #ccc" class="top-15">
			<Toolbar style="border-bottom: 1px solid #ccc" :editor="editorRef" :defaultConfig="toolbarConfig"
				:mode="mode" />
			<Editor style="height: 500px; overflow-y: hidden" v-model="valueHtml" :defaultConfig="editorConfig"
				:mode="mode" @onCreated="handleCreated" />
		</div>
		
		<el-table id="table" :data="tableData" class="top-15" style="width: 100%" :header-cell-style="headerCellStyle"
			:cell-style="cellStyle" border>
			<el-table-column prop="rowNum" label="序号" width="60" align="center" />
			<el-table-column prop="name" label="重要目标名称" />
			<el-table-column prop="contactPerson" label="联系人" />
			<el-table-column prop="contactNumber" label="联系电话" />
		</el-table>
		
		
		

		<div class="flex-justify-end top-20">
			<el-button type="primary" class="save-btn" @click="saveProgramme">保存</el-button>
		</div>
	</div>
</template>
<style scoped lang="scss"></style>